package zhihui.mobile.presenter.register;

import android.content.Context;
import android.text.TextUtils;

import com.zgm.utils.StringUtils;

import zhihui.mobile.R;
import zhihui.mobile.manager.register.RegisterManager;
import zhihui.mobile.ui.IView;

/**
 * Created by 张公铭 on 2017/7/8 0008.
 */

public class PhoneFragmentPresenter implements IPhoneFragmentContract.IPhoneFragmentPersenter
{
    private IPhoneFragmentContract.IPhoneFragmentView phoneFragmentView;
    private Context mContext;

    @Override
    public void init(IView view, Context context)
    {
        mContext = context;
        phoneFragmentView = (IPhoneFragmentContract.IPhoneFragmentView) view;
    }

    @Override
    public void onResume()
    {
        if (RegisterManager.getInstance().getCurRegister() != null && !TextUtils.isEmpty(RegisterManager.getInstance().getCurRegister().getPhone()))
        {
            phoneFragmentView.initPhone(RegisterManager.getInstance().getCurRegister().getPhone());
        }
        phoneFragmentView.showMessage("");
    }

    @Override
    public void onStart()
    {

    }

    @Override
    public void onPause()
    {

    }

    @Override
    public void onStop()
    {

    }

    @Override
    public void onDestroy()
    {

    }

    @Override
    public void goPhoneCodeFragment(String phone)
    {
        if (TextUtils.isEmpty(phone))
        {
            phoneFragmentView.showMessage(mContext.getString(R.string.phone_null));
            return;
        } else if (!StringUtils.isNumeric(phone) || phone.length() != 11)
        {
            phoneFragmentView.showMessage(mContext.getString(R.string.phone_error));
            return;
        }
        RegisterManager.getInstance().getCurRegister().setPhone(phone);
        phoneFragmentView.goPhoneCodeFragment();
    }
}
